/**
 * 
 */
package com.wodsy.phoenix.apps.cms.homepage.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.wodsy.phoenix.dataobject.base.Pager;
import com.wodsy.phoenix.dataobject.cms.model.IdxAdPic;
import com.wodsy.phoenix.dataservice.cms.service.CmsHomePageBannerService;

/**
 * @author bryan
 *
 */
@RequestMapping("/cmsBanner")
@Controller
public class CmsHomePageIndexBannerController {
	private Logger logger = LoggerFactory.getLogger(CmsHomePageIndexBannerController.class);
	@Autowired
	private CmsHomePageBannerService cmsHomePageBannerService;
	

	/**
     * 导向首页面
     *
     * @param request 请求
     * @return
     */
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index(HttpServletRequest request) {
    	
    	List<IdxAdPic> list = new  ArrayList<IdxAdPic>();
    	IdxAdPic idc = new IdxAdPic();
    	idc.setId(1);
    	list.add(idc);
    	ModelAndView model = new ModelAndView();
    	model.addObject("model", list);
        return "/banner";
    }
    /**
     * 导向首页面
     *
     * @param request 请求
     * @return
     */
    /*@RequestMapping(value = "/index2", method = RequestMethod.GET)
    public ModelAndView index2(HttpServletRequest request) {
    	
    	List<IdxAdPic> list = new  ArrayList<IdxAdPic>();
    	IdxAdPic idc = new IdxAdPic();
    	idc.setId(1);
    	list.add(idc);
    	ModelAndView model = new ModelAndView("/index");
    	model.addObject("model", list);
        return model;
    }*/
    
    /**
	 * 增加一条banner
	 */
    @RequestMapping(value = "/addOneBanner", method = RequestMethod.POST)
    @ResponseBody
	public void addOneBanner(IdxAdPic tbIdxAdPic){
    	tbIdxAdPic.setCreateTime(new Date());
		cmsHomePageBannerService.save(tbIdxAdPic);
	}
	/**
	 * 获取一条banner信息
	 */
    @RequestMapping(value = "/getOneBanner/{bannerId}", method = RequestMethod.GET)
    @ResponseBody
	public IdxAdPic getOneBanner(@PathVariable Integer bannerId){
		IdxAdPic tbIndexAdPic = cmsHomePageBannerService.get(bannerId);
		return tbIndexAdPic;
	}
	/**
	 * 修改一条banner信息
	 */
    @RequestMapping(value = "/updateOneBanner", method = RequestMethod.POST)
    @ResponseBody
	public void updateOneBanner(IdxAdPic tbIdxAdPic){
    	tbIdxAdPic.setUpdateTime(new Date());
		
		cmsHomePageBannerService.updateBannerRecommended(tbIdxAdPic);//.update(tbIdxAdPic);
	}
	
	/**
	 * 根据搜索条件查询bannerList
	 */
    @RequestMapping(value = "/getAllBannerByOrder", method = RequestMethod.POST)
    @ResponseBody
	public Pager<IdxAdPic> getAllBannerByOrder(int pageSize,int pageNo,IdxAdPic picreq){
		Pager<IdxAdPic> adPic = new Pager<>();
		
		Pager<IdxAdPic> picPager = cmsHomePageBannerService.searchBannerPicByOrder(adPic, picreq);

		return picPager;
	}
	/**
	 * 更新pic状态
	 */
    @RequestMapping(value = "/updatePicBannerStatus", method = RequestMethod.POST)
    @ResponseBody
	public void updatePicBannerStatus(Integer rbannerId,Integer status){
		cmsHomePageBannerService.updateBannerPicStatus(rbannerId, status);
	}
	/**
	 * 更新picList状态
	 */
    @RequestMapping(value = "/updatePicBannerStatusList", method = RequestMethod.POST)
    @ResponseBody
	public void updatePicBannerStatusList(Integer[] list,Integer status){
		cmsHomePageBannerService.updateBannerPicStatus(list, status);
	}
    
}
